package com.hktf.uilib.utils;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.drawerlayout.widget.DrawerLayout;


/* loaded from: C:\Users\yxky-077\灵动锁屏\classes04.dex */
public class StatusBarUtils {
    private Activity mActivity;
    private int mColor = -1;
    private int mContentResourseIdInDrawer;
    private Drawable mDrawable;
    private boolean mIsActionBar;
    private boolean mIsDrawerLayout;

    public StatusBarUtils(Activity activity) {
        this.mActivity = activity;
    }

    public static StatusBarUtils with(Activity activity) {
        return new StatusBarUtils(activity);
    }

    public int getColor() {
        return this.mColor;
    }

    public StatusBarUtils setColor(int i) {
        this.mColor = i;
        return this;
    }

    public Drawable getDrawable() {
        return this.mDrawable;
    }

    public StatusBarUtils setDrawable(Drawable drawable) {
        this.mDrawable = drawable;
        return this;
    }

    public boolean isDrawerLayout() {
        return this.mIsDrawerLayout;
    }

    public boolean isActionBar() {
        return this.mIsActionBar;
    }

    public StatusBarUtils setIsActionBar(boolean z) {
        this.mIsActionBar = z;
        return this;
    }

    public StatusBarUtils setDrawerLayoutContentId(boolean z, int i) {
        this.mIsDrawerLayout = z;
        this.mContentResourseIdInDrawer = i;
        return this;
    }

    public void init() {
        fullScreen(this.mActivity);
        int i = this.mColor;
        if (i != -1) {
            addStatusViewWithColor(this.mActivity, i);
        }
        Drawable drawable = this.mDrawable;
        if (drawable != null) {
            addStatusViewWithDrawble(this.mActivity, drawable);
        }
        if (isDrawerLayout()) {
            fitsSystemWindows(this.mActivity);
        }
        if (isActionBar()) {
//            ((ViewGroup) this.mActivity.getWindow().getDecorView().findViewById(16908290)).setPadding(0, getStatusBarHeight(this.mActivity) + getActionBarHeight(this.mActivity), 0, 0);
        }
    }

    public StatusBarUtils clearActionBarShadow() {
        ActionBar supportActionBar = ((AppCompatActivity) this.mActivity).getSupportActionBar();
        if (supportActionBar != null) {
            supportActionBar.setElevation(0.0f);
        }
        return this;
    }

    private void fitsSystemWindows(Activity activity) {
//        View childAt = ((ViewGroup) activity.findViewById(16908290)).getChildAt(0);
//        if (childAt != null) {
//            childAt.setFitsSystemWindows(true);
//            if (!(childAt instanceof DrawerLayout)) {
//                return;
//            }
//            ((DrawerLayout) childAt).setClipToPadding(false);
//        }
    }

    public static int getStatusBarHeight(Activity activity) {
        int identifier = activity.getResources().getIdentifier("status_bar_height", "dimen", "android");
        int dimensionPixelSize = identifier > 0 ? activity.getResources().getDimensionPixelSize(identifier) : 0;
        Log.e("getStatusBarHeight", dimensionPixelSize + "");
        return dimensionPixelSize;
    }

    public static int getActionBarHeight(Context context) {
        TypedValue typedValue = new TypedValue();
        context.getTheme().resolveAttribute(16843499, typedValue, true);
        return TypedValue.complexToDimensionPixelSize(typedValue.data, context.getResources().getDisplayMetrics());
    }

    public static void setStatusBarColor(Window window, int i) {
        window.addFlags(Integer.MIN_VALUE);
        window.setStatusBarColor(i);
    }

    private void addStatusViewWithColor(Activity activity, int i) {
//        if (isDrawerLayout()) {
//            View childAt = ((ViewGroup) activity.findViewById(16908290)).getChildAt(0);
//            LinearLayout linearLayout = new LinearLayout(activity);
//            linearLayout.setOrientation(1);
//            View view = new View(activity);
//            ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(-1, getStatusBarHeight(activity));
//            view.setBackgroundColor(i);
//            linearLayout.addView(view, layoutParams);
//            DrawerLayout drawerLayout = (DrawerLayout) childAt;
//            View findViewById = activity.findViewById(this.mContentResourseIdInDrawer);
//            drawerLayout.removeView(findViewById);
//            linearLayout.addView(findViewById, findViewById.getLayoutParams());
//            drawerLayout.addView(linearLayout, 0);
//            return;
//        }
//        ((ViewGroup) this.mActivity.getWindow().getDecorView().findViewById(16908290)).setPadding(0, getStatusBarHeight(this.mActivity), 0, 0);
//        activity.getWindow().setStatusBarColor(i);
    }

    private void addStatusViewWithDrawble(Activity activity, Drawable drawable) {
//        View view = new View(activity);
//        ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(-1, getStatusBarHeight(activity));
//        view.setBackground(drawable);
//        if (isDrawerLayout()) {
//            View childAt = ((ViewGroup) activity.findViewById(16908290)).getChildAt(0);
//            LinearLayout linearLayout = new LinearLayout(activity);
//            linearLayout.setOrientation(1);
//            linearLayout.addView(view, layoutParams);
//            DrawerLayout drawerLayout = (DrawerLayout) childAt;
//            View findViewById = activity.findViewById(this.mContentResourseIdInDrawer);
//            drawerLayout.removeView(findViewById);
//            linearLayout.addView(findViewById, findViewById.getLayoutParams());
//            drawerLayout.addView(linearLayout, 0);
//            return;
//        }
//        ((ViewGroup) this.mActivity.getWindow().getDecorView()).addView(view, layoutParams);
//        ((ViewGroup) this.mActivity.getWindow().getDecorView().findViewById(16908290)).setPadding(0, getStatusBarHeight(this.mActivity), 0, 0);
    }

    public static void fullScreen(Activity activity) {
        Window window = activity.getWindow();
        View decorView = window.getDecorView();
//        window.clearFlags(DownloadExpSwitchCode.BACK_BUGFIX_SIGBUS);
//        decorView.setSystemUiVisibility(LogType.UNEXP_ANR);
        window.addFlags(Integer.MIN_VALUE);
        window.setStatusBarColor(0);
    }

    public static void setStatusTransparent(Activity activity) {
        Window window = activity.getWindow();
        WindowManager.LayoutParams attributes = window.getAttributes();
        attributes.flags = 134217728 | attributes.flags;
        window.setAttributes(attributes);
        window.getDecorView().setSystemUiVisibility(1792);
        window.addFlags(Integer.MIN_VALUE);
        window.setStatusBarColor(0);
        window.setNavigationBarColor(0);
    }
}
